package com.infore.siteManagement.repository;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.infore.siteManagement.entity.ProjectAndStation;

@Repository
public interface IProjectAndStationRepository extends JpaRepository<ProjectAndStation, String>,JpaSpecificationExecutor<ProjectAndStation>{

	List<ProjectAndStation> findByStationCodeIn(List<String> stationId);
	
	@Modifying
	@Transactional
	int deleteByStationCodeIn(List<String> stationCodes);
	
	/**通过因子删除中间表**/
	@Modifying
	@Transactional 
	int deleteByProjectCodeIn(List<String> projectCodes);
	
	/**
	 * 查询站点下因子并通过因子编号排序
	 */
	@Query(value="select distinct t.project_code,p.sort_index from PROJECT_AND_STATION t left join project p on p.project_code = t.project_code " + 
			"where t.station_code in :stationId order by p.sort_index asc",nativeQuery = true)
	List<Map<String, Object>> QueryByStationCodeIn(@Param("stationId")List<String> stationId);
}
